package cn.tedu;

//面向对象的练习
public class TextCar {
    public static void main(String[] args) {
        Car c = new Car();
        //对象c设置属性值
//        c.color="黑色";
//        c.brand="BMW";
//        c.length=0.2;
//        c.price=200;
        //查看属性值
//        System.out.println(c.brand);
//        System.out.println(c.color);
//        System.out.println(c.length);
//        System.out.println(c.price);
        //调用c的方法
//        c.start();
//        c.stop();
        //调用SET和GET方法，设置获取属性值
        c.setBrand("特斯拉");
        c.setColor("black");
        c.setLength(3);
        c.setPrice(200.01);
        System.out.println(c.getBrand());
        System.out.println(c.getColor());
        System.out.println(c.getLength());
        System.out.println(c.getPrice());
        //调用公共方法来调用私有方法
        c.start();

    }

}

//Car类属性和行为
class Car {
    //属性——成员变量
    private String color;
    private String brand;
    private double price;
    private double length;

    //右击——Generate——Getter and Setter——shift全选ok即可
    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    //行为——方法
    //本类中公共方法调用私有方法
    public void start() {
        System.out.println("开动");
        stop();//调用私有方法
    }

    //通过private修饰封装
    private void stop() {
        System.out.println("停止");
    }
}